﻿// owner 蒋家伟

#include "IGenericElement.h"

#include "Document.h"
#include "GenericElement.h"
#include "Dbg_Warn_Define.h"

using namespace jsdk;

jsdk::IElement* jsdk::IGenericElement::create(
    IDocument* pDoc, 
    const UniqueId& typeUid, 
    OwnerPtr<IExternalData> opExternalData, 
    bool isTemp /*= false*/)
{
    OwnerPtr<IElement> opElement = GenericElement::create(typeUid, transformOwnerShip(opExternalData), isTemp);
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opElement, L"通用对象创建失败", L"蒋家伟", L"2023-12-19");

    Document* pDocImp = quick_cast<Document>(pDoc);
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pDocImp, L"文档类别转换失败", L"蒋家伟", L"2023-12-19");
    IElement* pElement = opElement.get();
    if (pDocImp->AddElement(transformOwnerShip(opElement)))
    {
        return pElement;
    }
    return nullptr;
}
